﻿namespace UnityEditor
{
    using System;
    using System.Runtime.CompilerServices;
    using UnityEngine;

    public sealed class Undo
    {
        private static string s_UndoName;
        private static UnityEngine.Object s_UndoObject;
        private static UnityEngine.Object[] s_UndoObjects;

        public static void ClearSnapshotTarget()
        {
            s_UndoName = null;
            s_UndoObjects = null;
            s_UndoObject = null;
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void ClearUndo(UnityEngine.Object identifier);
        public static void CreateSnapshot()
        {
            CreateSnapshot(s_UndoObject, s_UndoObjects, s_UndoName);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void CreateSnapshot(UnityEngine.Object singleObject, UnityEngine.Object[] objects, string name);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void IncrementCurrentEventIndex();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void PerformRedo();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal static extern void PerformTemporaryUndoStack();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void PerformUndo();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void RegisterCreatedObjectUndo(UnityEngine.Object objectToUndo, string name);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void RegisterSceneUndo(string name);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void RegisterSetTransformParentUndo(Transform transform, Transform newParent, string name);
        public static void RegisterSnapshot()
        {
            RegisterSnapshot(s_UndoObject, s_UndoObjects, s_UndoName);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void RegisterSnapshot(UnityEngine.Object identifier, UnityEngine.Object[] objects, string name);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal static extern void RegisterTemporaryUndoStack();
        public static void RegisterUndo(UnityEngine.Object[] objectsToUndo, string name)
        {
            if (objectsToUndo.Length > 0)
            {
                RegisterUndoMultiple(objectsToUndo[0], objectsToUndo, name, 0);
            }
        }

        public static void RegisterUndo(UnityEngine.Object objectToUndo, string name)
        {
            RegisterUndo(objectToUndo, name, 0);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal static extern void RegisterUndo(UnityEngine.Object objectToUndo, string name, int namePriority);
        internal static void RegisterUndo(UnityEngine.Object[] objectsToUndo, string name, int namePriority)
        {
            if (objectsToUndo.Length > 0)
            {
                RegisterUndoMultiple(objectsToUndo[0], objectsToUndo, name, namePriority);
            }
        }

        internal static void RegisterUndo(UnityEngine.Object identifier, UnityEngine.Object[] objectsToUndo, string name)
        {
            RegisterUndoMultiple(identifier, objectsToUndo, name, 0);
        }

        internal static void RegisterUndo(UnityEngine.Object identifier, UnityEngine.Object[] objectsToUndo, string name, int namePriority)
        {
            RegisterUndoMultiple(identifier, objectsToUndo, name, namePriority);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void RegisterUndoMultiple(UnityEngine.Object identifier, UnityEngine.Object[] objectsToUndo, string name, int namePriority);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void RestoreSnapshot();
        public static void SetSnapshotTarget(UnityEngine.Object[] objectsToUndo, string name)
        {
            s_UndoName = name;
            s_UndoObjects = objectsToUndo;
            s_UndoObject = null;
        }

        public static void SetSnapshotTarget(UnityEngine.Object objectToUndo, string name)
        {
            s_UndoName = name;
            s_UndoObjects = null;
            s_UndoObject = objectToUndo;
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal static extern void SetTemporaryUndoStackEnabled(bool enable);
    }
}

